package com.ujiuye.utils;

import com.ujiuye.pojo.Student;

import java.util.List;

public class PageTools {

    private int currentPage;//当前页
    private int pageSize;//每页显示的条数
    private int sumSize;//总条数

    private int index;//索引
    private int prePage;//上一页
    private int nextPage;//下一页
    private int sumPage;//总页数


    //存学生信息
    private List<Student> studentList;


    //提供构造方法  需要传递三个基础的参数
    public PageTools(int currentPage,int pageSize,int sumSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.sumSize = sumSize;

        //索引的计算
        index = (currentPage - 1) * pageSize;

        //上一页的计算
        prePage = currentPage == 1 ? 1 : currentPage - 1;

        //计算总页数
        sumPage = sumSize / pageSize + (sumSize % pageSize == 0 ? 0 : 1);

        //下一页
        nextPage = currentPage == sumPage ? currentPage : (currentPage + 1);


    }


    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getSumSize() {
        return sumSize;
    }

    public void setSumSize(int sumSize) {
        this.sumSize = sumSize;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int getSumPage() {
        return sumPage;
    }

    public void setSumPage(int sumPage) {
        this.sumPage = sumPage;
    }

    @Override
    public String toString() {
        return "PageTools{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", sumSize=" + sumSize +
                ", index=" + index +
                ", prePage=" + prePage +
                ", nextPage=" + nextPage +
                ", sumPage=" + sumPage +
                ", studentList=" + studentList +
                '}';
    }
}
